import asyncio
import time

import aiohttp


# async def main():
#     print('1')
#     await asyncio.sleep(2)
#     print('2')
# main_task = main()
# r  = asyncio.run(main_task)
# print(main_task)
# print('33')





# async  def task(num):
#     print(f'{num}任务开始')
#
#     await asyncio.sleep(2)
#
#     print(f'{num}任务结束')
#
# async def main():
#     task1 = [task(i) for i in range(10)]
#     await  asyncio.gather(*task1)
#
# asyncio.run(main())







async  def fetch(session,url):
    async  with session.get(url) as response:
        return await response.json()

async  def main():
    async with aiohttp.ClientSession() as session:
        result = await asyncio.gather(*[fetch(session,f"https://httpbin.org/get?age={i}" )for i in range(10)])
        for i in result:
            print(i)
start = time.time()
asyncio.run(main())



print(f'时间消耗是{time.time()-start}')





# async def main():
#     pass
#
# r = main()
# print(type(r))